xtask\tasks\fmt/
verify_flowey.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::Xtask;
5use anyhow::Context;
6use clap::Parser;
7
8#[derive(Parser)]
9#[clap(about = "Ensure all flowey pipelines are up to date")]
10pub struct VerifyFlowey {
11    /// Fix any out-of-date pipelines
12    #[clap(long)]
13    pub fix: bool,
14}
15
16impl VerifyFlowey {
17    pub fn new(fix: bool) -> Self {
18        Self { fix }
19    }
20}
21
22impl Xtask for VerifyFlowey {
23    fn run(self, ctx: crate::XtaskCtx) -> anyhow::Result<()> {
24        // need to go through all this rigamarole because `cargo --quiet
25        // xflowey regen` doesn't do what you'd hope it'd do
26        let cmd = {
27            let data = fs_err::read_to_string(ctx.root.join(".cargo/config.toml"))?;
28            let mut cmd = None;
29            for ln in data.lines() {
30                if let Some(ln) = ln.trim().strip_prefix(r#"xflowey = ""#) {
31                    let alias = ln
32                        .strip_suffix('"')
33                        .context("invalid .cargo/config.toml")?
34                        .split(' ')
35                        .map(|s| s.to_owned())
36                        .collect::<Vec<_>>();
37                    cmd = Some(alias);
38                }
39            }
40            cmd.context("could not find `xflowey` alias in .cargo/config.toml")?
41        };
42
43        let check = (!self.fix).then_some("--check");
44
45        let sh = xshell::Shell::new()?;
46        xshell::cmd!(sh, "cargo --quiet {cmd...} regen --quiet {check...}")
47            .quiet()
48            .run()?;
49
50        Ok(())
51    }
52}